package com.ruoyi.ems.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.ems.domain.EmsScoreDetails;
import com.ruoyi.ems.service.IEmsScoreDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分数明细Controller
 * 
 * @author sh
 * @date 2023-12-12
 */
@RestController
@RequestMapping("/ems/score_details")
public class EmsScoreDetailsController extends BaseController
{
    @Autowired
    private IEmsScoreDetailsService emsScoreDetailsService;

    /**
     * 查询分数明细列表
     */
    @PreAuthorize("@ss.hasPermi('ems:score_details:list')")
    @GetMapping("/list")
    public TableDataInfo list(EmsScoreDetails emsScoreDetails)
    {
        startPage();
        List<EmsScoreDetails> list = emsScoreDetailsService.selectEmsScoreDetailsList(emsScoreDetails);
        return getDataTable(list);
    }

    /**
     * 导出分数明细列表
     */
    @PreAuthorize("@ss.hasPermi('ems:score_details:export')")
    @Log(title = "分数明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EmsScoreDetails emsScoreDetails)
    {
        List<EmsScoreDetails> list = emsScoreDetailsService.selectEmsScoreDetailsList(emsScoreDetails);
        ExcelUtil<EmsScoreDetails> util = new ExcelUtil<EmsScoreDetails>(EmsScoreDetails.class);
        util.exportExcel(response, list, "分数明细数据");
    }

    /**
     * 获取分数明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('ems:score_details:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(emsScoreDetailsService.selectEmsScoreDetailsById(id));
    }

    /**
     * 新增分数明细
     */
    @PreAuthorize("@ss.hasPermi('ems:score_details:add')")
    @Log(title = "分数明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EmsScoreDetails emsScoreDetails)
    {
        return toAjax(emsScoreDetailsService.insertEmsScoreDetails(emsScoreDetails));
    }

    /**
     * 修改分数明细
     */
    @PreAuthorize("@ss.hasPermi('ems:score_details:edit')")
    @Log(title = "分数明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EmsScoreDetails emsScoreDetails)
    {
        return toAjax(emsScoreDetailsService.updateEmsScoreDetails(emsScoreDetails));
    }

    /**
     * 删除分数明细
     */
    @PreAuthorize("@ss.hasPermi('ems:score_details:remove')")
    @Log(title = "分数明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(emsScoreDetailsService.deleteEmsScoreDetailsByIds(ids));
    }
}
